﻿#include "utils.h"
#include <QSettings>
#include <QCoreApplication>

// Windows 启动项注册表路径
static const QString AUTOSTART_KEY = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";

bool Utils::setAutoStart(bool enable)
{
    QSettings settings(AUTOSTART_KEY, QSettings::NativeFormat);
    QString appName = "EMQX Manager";
    QString appPath = "\"" + QCoreApplication::applicationFilePath().replace("/", "\\") + "\"";

    if (enable) {
        settings.setValue(appName, appPath);
    } else {
        settings.remove(appName);
    }
    return true;
}

bool Utils::isAutoStart()
{
    QSettings settings(AUTOSTART_KEY, QSettings::NativeFormat);
    QString appName = "EMQX Manager";
    return settings.contains(appName);
}
